/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.eurotrader.validadores;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author PROG01
 */
public class ValidarData implements Validator {

    public void validate(FacesContext context, UIComponent validate, Object value) throws ValidatorException {
        Date data = (Date) value;
        // java.sql.Date dataw = new java.sql.Date(data.getTime());
        //Calendar.getInstance().;
    //    Calendar cal = Calendar.getInstance();
     //   cal.setTimeInMillis(System.currentTimeMillis());
  //      Date dataSemHora = new Date(new java.sql.Date(System.currentTimeMillis()).getTime());
        Calendar data1 = Calendar.getInstance();
        Calendar data2 = new GregorianCalendar(data1.get(Calendar.YEAR), data1.get(Calendar.MONTH), data1.get(Calendar.DATE));
        //   Calendar cal = Calendar.getInstance().;
        //  java.sql.Date dataHj = new java.sql.Date(System.currentTimeMillis());

        //   System.out.println(data.toString());
        //      System.out.println(cal.getTime().toString());
        if (data.before(data2.getTime())) {
            ((UIInput) validate).setValid(false);
            FacesMessage msg = new FacesMessage("Data Inválida");
            context.addMessage(validate.getClientId(context), msg);
        }


    }
}
